﻿/*
 * Copyright 2008 Pimm Hogeling, Karim Sempel and Demian Sempel
 * 
 * This file is part of 8bitplays.
 * 
 * 8bitplays is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * 8bitplays is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with 8bitplays. If not, see <http://www.gnu.org/licenses/>.
 */
package nl.sandmen.team.tray {
	import flash.display.NativeMenu;
	import flash.display.NativeMenuItem;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import nl.sandmen.team.events.TrayMenuEvent;
	/**
	 * @author Team Sandmen
	 */
	public class TrayMenu {
		private static var _trayMenu:NativeMenu;
		public static var trayEventDispatcher:EventDispatcher = new EventDispatcher();
		public static function get trayMenu():NativeMenu {
			if (_trayMenu) {
				return _trayMenu;
			}
			_trayMenu = new NativeMenu();
			var aboutItem:NativeMenuItem = new NativeMenuItem("About");
			aboutItem.addEventListener(Event.SELECT, about);
			_trayMenu.addItem(aboutItem);
			_trayMenu.addItem(new NativeMenuItem("", true));
			var showHideItem:NativeMenuItem = new NativeMenuItem("Show/Hide");
			showHideItem.addEventListener(Event.SELECT, showHide);
			_trayMenu.addItem(showHideItem);
			var exitItem:NativeMenuItem = new NativeMenuItem("Exit");
			exitItem.addEventListener(Event.SELECT, exit);
			_trayMenu.addItem(exitItem);
			return _trayMenu;
		}
		private static function about(e:Event):void {
			trayEventDispatcher.dispatchEvent(new TrayMenuEvent(TrayMenuEvent.ABOUT));
		}
		private static function exit(e:Event):void {
			trayEventDispatcher.dispatchEvent(new TrayMenuEvent(TrayMenuEvent.EXIT));
		}
		private static function showHide(e:Event):void {
			trayEventDispatcher.dispatchEvent(new TrayMenuEvent(TrayMenuEvent.SHOW_HIDE));
		}
	}
}